<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Barrera_model extends CI_Model 
{
	
        public function get_usuaris()
        {
            $usuaris = $this->db->get('usuaris')->result_array();
            return $usuaris;
        }
        
        public function add_usuari($nom,$telefon,$validesa)
        {
            $nou = array(
                'nom' => $nom,
                'telefon' => $telefon,
                'validesa' => $validesa
            );
            
            $this->db->insert('usuaris',$nou);
        }
        
        public function del_usuari($id)
        {
            $del = array(
                'id' => $id
            );
            $this->db->delete('usuaris',$del);
        }
	
	public function add_user($email, $password)
	{
		$query = $this->db->get_where('users', array('email' => $email));
		if($query->num_rows == 1){
			return FALSE;
		}
		$this->db->insert('users', array('email' => $email, 'password' => md5($password))); 
		return TRUE;
	}
	
	public function delete_user($email)
	{
		$uid = $this->db->get_where('users', array('email' => $email))->row()->uid;
		$this->db->delete('contacts', array('uid' => $uid));
		
		$this->db->delete('users', array('email' => $email));
	}
	
	public function update_user($email, $password)
	{
		$this->db->update('users', array('password' => md5($password)), array('email' => $email));
	}
}
